package com.jhhc.Config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;

/**
 * @Author ZhangLe 注意这个扫描的包 你的不同mapper那个数据库使用写在对应的包下 对POJO service无关
 * @Date 2020/11/20 19:48
 */

@Configuration
@MapperScan(value = {"com.jhhc.FloodForecast.BaseInfo.Dao", "com.jhhc.FloodForecast.Calculate.Condition.Dao", "com.jhhc.FloodForecast.OperationModel.Dao"
        , "com.jhhc.FloodForecast.ForecastModel.Dao","com.jhhc.FloodForecast.Sensor.Dao",
        "com.jhhc.BDMS.Data.Dao","com.jhhc.FloodForecast.Calculate.Forecast.Dao","com.jhhc.BDMS.System.Dao"}, sqlSessionFactoryRef = "sqlSessionFactory2")
public class FloodConfig {
    /**
     * 和总配置文件注入bean名称一致 其他无需修改
     */
    @Autowired
    @Qualifier("floodDataSource")
    private DataSource ds2;

    @Bean(name = "sqlSessionFactory2")
    @Primary
    public SqlSessionFactory sqlSessionFactory2() throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(ds2);
        return sqlSessionFactoryBean.getObject();
    }

    @Bean
    @Primary
    public SqlSessionTemplate sqlSessionTemplate2() throws Exception {
        SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory2());
        return sqlSessionTemplate;
    }

}
